<template>
  <div v-if="page.list.length === 0" class="no-data">暂无数据</div>
  <el-table v-else v-loading="page.loading" :data="page.list">
    <el-table-column :min-width="100" label="考试时间">
      <template #default="scope"> {{ scope.row.gmtCreate }} </template>
    </el-table-column>
    <el-table-column label="作答时长">
      <template #default="scope"> {{ formatTime(scope.row.userAnswerTime) }} </template>
    </el-table-column>
    <el-table-column label="阅卷状态">
      <template #default="scope">
        <common-enum-view :enum-name="'ExamStatus'" :enum-value="scope.row.examStatus" />
      </template>
    </el-table-column>
    <el-table-column label="考试结果">
      <template #default="scope">
        <span v-if="props.resultShow">
          <common-enum-view :enum-name="'PassStatus'" :enum-value="scope.row.passStatus" />
        </span>
        <span v-if="!props.resultShow">/</span>
      </template>
    </el-table-column>
    <el-table-column label="成绩得分">
      <template #default="scope">
        <span v-if="props.resultShow"> {{ scope.row.userScore }} 分 </span>
        <span v-if="!props.resultShow">/</span>
      </template>
    </el-table-column>
    <el-table-column :width="100" label="操作">
      <template #default="scope">
        <el-button link type="primary" @click="handleReport(scope.row.id)">查看报告</el-button>
      </template>
    </el-table-column>
  </el-table>
  <common-pagination v-model:current-page="page.pageCurrent" v-model:page-size="page.pageSize" :total="page.totalCount" @pagination="handlePage" />
</template>
<script setup>
  import useTable from '~/utils/table.js'
  import { examApi } from '~/api/exam'
  import { formatTime } from '~/utils/base'

  const props = defineProps({
    examType: { type: Number, default: undefined },
    relateId: { type: String, default: '' },
    resultShow: { type: Boolean, default: false }
  })

  // 查看报告
  const handleReport = (recordId) => {
    useRouter().push({ name: 'exam-report', query: { id: props.relateId, recordId: recordId } })
  }

  const { page, handlePage } = useTable(
    {
      page: examApi.examRecordPage
    },
    {
      examType: props.examType,
      relateId: props.relateId
    }
  )
</script>
<style lang="scss" scoped></style>
